using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace shuju_jiange.Com
{
    public class Data
    {
        private static int seed = 0;
        private string _srcData = "";        
        private int _interval;
        private List<int> _deviation = new List<int>();
        private int _time;
        private int _sum;
        private float _sum_percent;
        private int _ac;
        private float _ac_percent;
        private int _bg;
        private float _bg_percent;
        private int _h;
        private float _h_percent;
        private int _bac2;
        private float _bac2_percent;
        private int _bbg2;
        private float _bbg2_percent;
        private int _ach2;
        private float _ach2_percent;
        private int _bgh2;
        private float _bgh2_percent;
        private int _bgh3;
        private float _bgh3_percent;

        //新添加数据
        private int _aac2;
        private float _aac2_percent;
        private int _abg2;
        private float _abg2_percent;

        //衍生数据
        private int _a1;
        private float _a1_percent;
        private int _a2;
        private float _a2_percent;
        private int _a3;
        private float _a3_percent;
        private int _a4;
        private float _a4_percent;
        private int _a5;
        private float _a5_percent;
        private int _a6;
        private float _a6_percent;
        private int _b1;
        private float _b1_percent;
        private int _b2;
        private float _b2_percent;
        private int _b3;
        private float _b3_percent;
        private int _b4;
        private float _b4_percent;
        private int _b5;
        private float _b5_percent;
        private int _b6;
        private float _b6_percent;


        private string[] _sumByItems = new string[] { };
        private DataList _owerList;
        private int _id;

        //新增
        private int _maxlen;
        private int _cha;
        private float _cha_percent;
        private int _blue;
        private int _red;
        private float _zhanyoulv;
        private int _chazhi;//计算占有率用

        // 静态属性：存储最新的原始数据列表
        public static List<string> CurrentRawDataList = null;

        // 新增功能相关属性
        private float _theoreticalInterval; // 理论间隔
        private float _zValue; // Z值
        private float _newDataIntervalY; // 新数据间隔Y
        private float _newEndDiffX; // 新末端差X
        private float _diffValue; // 差值 = 理论间隔 - Z值
        private bool _isAnomalyValue; // 是否为异常值
        private bool _isNewAnomalyValue; // 是否为新异常值
        private float _columnX; // 列X = X-(z值*次数+理论间隔)

        public Data()
        {
            _id = seed++;
        }
        public static int Seed { get { return seed; }set { seed = value;} }
        public int Id { get {
                return _id;
            } }
        /// <summary>
        /// 原始数据
        /// </summary>
        public string SrcData
        {
            get { return _srcData; }
            set
            {
                if(value!=null && !value.Equals(_srcData))
                {
                    if (value.Contains('-'))
                    {
                        string[] ss = value.Split('-');
                        foreach(var s in ss)
                        {
                            int p;
                            if (int.TryParse(s, out p))
                            {
                                _deviation.Add(p);
                            }
                        }
                    }
                    else
                    {
                        char[] temp = value.ToArray();

                        // 设置偏移数据
                        _deviation.Clear();
                        for (int i = 0; i < temp.Length; i++)
                        {
                            int p;
                            if (int.TryParse(temp[i].ToString(), out p))
                            {
                                _deviation.Add(i * 10 + p);
                            }
                        }
                    }
                    
                    // 设置AC数据
                    List<int> _listAC = new List<int>();
                    foreach (int sNum in _deviation)
                    {
                        foreach (int eNum in _deviation)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listAC.Contains(result))
                            {
                                _listAC.Add(result);
                            }
                        }
                    }
                    _ac = Math.Abs(_listAC.Count - _deviation.Count);
                    // 设置BG数据
                    List<int> _listBG = new List<int>();
                    foreach (int sNum in _deviation)
                    {
                        foreach (int eNum in _deviation)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listBG.Contains(result))
                            {
                                _listBG.Add(result);
                            }
                        }
                    }
                    _bg = Math.Abs(_listBG.Count - _deviation.Count);
                    // 设置H数据
                    _h = 0;
                    foreach(int item in _deviation)
                    {
                        _h += item;
                    }


                    //设置差值
                   // _cha = 0;

                    //foreach (int item in _deviation)
                    //{
                    //    _cha += item-1;
                    //}

                    // 通过BG计算的中间数据计算BAC2数据
                    List<int> _listBAC2 = new List<int>();
                    foreach (int sNum in _listBG)
                    {
                        foreach (int eNum in _listBG)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listBAC2.Contains(result))
                            {
                                _listBAC2.Add(result);
                            }
                        }
                    }
                    _bac2 = Math.Abs(_listBAC2.Count - _listBG.Count);
                    // 通过BG计算的中间数据计算BBG2数据
                    List<int> _listBBG2 = new List<int>();
                    foreach (int sNum in _listBG)
                    {
                        foreach (int eNum in _listBG)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listBBG2.Contains(result))
                            {
                                _listBBG2.Add(result);
                            }
                        }
                    }
                    _bbg2 = Math.Abs(_listBBG2.Count - _listBG.Count);

                    // 通过AG计算的中间数据计算AAC2数据
                    List<int> _listAAC2 = new List<int>();
                    foreach (int sNum in _listAC)
                    {
                        foreach (int eNum in _listAC)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listAAC2.Contains(result))
                            {
                                _listAAC2.Add(result);
                            }
                        }
                    }
                    _aac2 = Math.Abs(_listAAC2.Count - _listAC.Count);
                    // 通过BG计算的中间数据计算ABG2数据
                    List<int> _listABG2 = new List<int>();
                    foreach (int sNum in _listAC)
                    {
                        foreach (int eNum in _listAC)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listABG2.Contains(result))
                            {
                                _listABG2.Add(result);
                            }
                        }
                    }
                    _abg2 = Math.Abs(_listABG2.Count - _listAC.Count);

                    //设置衍生数据规则
                    //a1
                    List<int> _listA1 = new List<int>();
                    foreach (int sNum in _listAAC2)
                    {
                        foreach (int eNum in _listAAC2)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listA1.Contains(result))
                            {
                                _listA1.Add(result);
                            }
                        }
                    }
                    _a1 = Math.Abs(_listA1.Count - _listAAC2.Count);
                    //a2
                    _a2 = 0;
                    foreach (int item in _listAAC2)
                    {
                        _a2 += item;
                    }
                    //a3
                    List<int> _listA3 = new List<int>();
                    foreach (int sNum in _listAAC2)
                    {
                        foreach (int eNum in _listAAC2)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listA3.Contains(result))
                            {
                                _listA3.Add(result);
                            }
                        }
                    }
                    _a3 = Math.Abs(_listA3.Count - _listAAC2.Count);

                    //a4
                    List<int> _listA4 = new List<int>();
                    foreach (int sNum in _listABG2)
                    {
                        foreach (int eNum in _listABG2)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listA4.Contains(result))
                            {
                                _listA4.Add(result);
                            }
                        }
                    }
                    _a4 = Math.Abs(_listA4.Count - _listABG2.Count);
                    //a5
                    _a5 = 0;
                    foreach (int item in _listABG2)
                    {
                        _a5 += item;
                    }
                    //a6
                    List<int> _listA6 = new List<int>();
                    foreach (int sNum in _listABG2)
                    {
                        foreach (int eNum in _listABG2)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listA6.Contains(result))
                            {
                                _listA6.Add(result);
                            }
                        }
                    }
                    _a6 = Math.Abs(_listA6.Count - _listABG2.Count);

                    //b1
                    List<int> _listB1 = new List<int>();
                    foreach (int sNum in _listBAC2)
                    {
                        foreach (int eNum in _listBAC2)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listB1.Contains(result))
                            {
                                _listB1.Add(result);
                            }
                        }
                    }
                    _b1 = Math.Abs(_listB1.Count - _listBAC2.Count);
                    //b2
                    _b2 = 0;
                    foreach (int item in _listBAC2)
                    {
                        _b2 += item;
                    }
                    //b3
                    List<int> _listB3 = new List<int>();
                    foreach (int sNum in _listBAC2)
                    {
                        foreach (int eNum in _listBAC2)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listB3.Contains(result))
                            {
                                _listB3.Add(result);
                            }
                        }
                    }
                    _b3 = Math.Abs(_listB3.Count - _listBAC2.Count);

                    //b4
                    List<int> _listB4 = new List<int>();
                    foreach (int sNum in _listBBG2)
                    {
                        foreach (int eNum in _listBBG2)
                        {
                            int result = Math.Abs(sNum - eNum);
                            if (!_listB4.Contains(result))
                            {
                                _listB4.Add(result);
                            }
                        }
                    }
                    _b4 = Math.Abs(_listB4.Count - _listBBG2.Count);
                    //a5
                    _b5 = 0;
                    foreach (int item in _listBBG2)
                    {
                        _b5 += item;
                    }
                    //a6
                    List<int> _listB6 = new List<int>();
                    foreach (int sNum in _listBBG2)
                    {
                        foreach (int eNum in _listBBG2)
                        {
                            int result = Math.Abs(sNum ^ eNum);
                            if (!_listB6.Contains(result))
                            {
                                _listB6.Add(result);
                            }
                        }
                    }
                    _b6 = Math.Abs(_listB6.Count - _listBBG2.Count);






                    // 设置ACH2数据
                    _ach2 = 0;
                    foreach (int item in _listAC)
                    {
                        _ach2 += item;
                    }
                    // 设置BGH2数据
                    _bgh2 = 0;
                    foreach (int item in _listBG)
                    {
                        _bgh2 += item;
                    }
                    // 设置BGH3数据
                    _bgh3 = 0;
                    foreach (int item in _listBAC2)
                    {
                        _bgh3 += item;
                    }
                }
                _srcData = value;
            }
        }
        /// <summary>
        /// 间隔
        /// </summary>
        public int Interval { get { return _interval; } set { _interval = value; } }
        /// <summary>
        /// 偏移数据
        /// </summary>
        public List<int> Deviation { get { return _deviation; } }
        /// <summary>
        /// 次数
        /// </summary>
        public int Time { get { return _time; } set { _time = value; } }
        /// <summary>
        /// 值相加%
        /// </summary>
        public float Sum_percent { get { return _sum_percent; } }
        /// <summary>
        /// AC数据
        /// </summary>
        public int Ac { get { return _ac; } }
        /// <summary>
        /// AC%
        /// </summary>
        public float Ac_percent { get { return _ac_percent; } }
        /// <summary>
        /// BG数据
        /// </summary>
        public int Bg { get { return _bg; } }
        /// <summary>
        /// BG%
        /// </summary>
        public float Bg_percent { get { return _bg_percent; } }
        /// <summary>
        /// H数据
        /// </summary>
        public int H { get { return _h; } }
        /// <summary>
        /// H%
        /// </summary>
        public float H_percent { get { return _h_percent; } }

        public int Cha { get { return _cha; } set { _cha = value; } }

        public int ChaZhi { get { return _chazhi; } set { _chazhi = value; } }

        public float Zhanyoulv { get { return _zhanyoulv; } set { _zhanyoulv = value; } }
        
        public int Maxlen { get { return _maxlen; } set { _maxlen = value; } }

        public int Blue { get { return _blue; } set { _blue = value; } }
        public int Red { get { return _red; } set { _red = value; } }
        /// <summary>
        /// H%
        /// </summary>
        public float Cha_percent { get { return _cha_percent; } }


        /// <summary>
        /// AC2数据
        /// </summary>
        public int BAc2 { get { return _bac2; } }
        /// <summary>
        /// AC2%
        /// </summary>
        public float BAc2_percent { get { return _bac2_percent; } }
        /// <summary>
        /// BG2数据
        /// </summary>
        public int BBg2 { get { return _bbg2; } }
        /// <summary>
        /// BG2%
        /// </summary>
        public float BBg2_percent { get { return _bbg2_percent; } }


          public int AAc2 { get { return _aac2; } }
        /// <summary>
        /// AC2%
        /// </summary>
        public float AAc2_percent { get { return _aac2_percent; } }
        /// <summary>
        /// BG2数据
        /// </summary>
        public int ABg2 { get { return _abg2; } }
        /// <summary>
        /// BG2%
        /// </summary>
        public float ABg2_percent { get { return _abg2_percent; } }


        /// <summary>
        /// BGH2数据
        /// </summary>
        public int Bgh2 { get { return _bgh2; } }
        /// <summary>
        /// BGH2%
        /// </summary>
        public float Bgh2_percent { get { return _bgh2_percent; } }
        /// <summary>
        /// BGH3数据
        /// </summary>
        public int Bgh3 { get { return _bgh3; } }
        /// <summary>
        /// BGH3%
        /// </summary>
        public float Bgh3_percent { get { return _bgh3_percent; } }
        /// <summary>
        /// Ach2
        /// </summary>
        public int Ach2 { get { return _ach2; } }
        /// <summary>
        /// Ach2%
        /// </summary>
        public float Ach2_percent { get { return _ach2_percent; } }



        public int A1 { get { return _a1; } }
        public int A2 { get { return _a2; } }
        public int A3 { get { return _a3; } }
        public int A4 { get { return _a4; } }
        public int A5 { get { return _a5; } }
        public int A6 { get { return _a6; } }


        public int B1 { get { return _b1; } }
        public int B2 { get { return _b2; } }
        public int B3 { get { return _b3; } }
        public int B4 { get { return _b4; } }
        public int B5 { get { return _b5; } }
        public int B6 { get { return _b6; } }
        public float A1_percent { get { return _a1_percent; } }
        public float A2_percent { get { return _a2_percent; } }
        public float A3_percent { get { return _a3_percent; } }
        public float A4_percent { get { return _a4_percent; } }
        public float A5_percent { get { return _a5_percent; } }
        public float A6_percent { get { return _a6_percent; } }

        public float B1_percent { get { return _b1_percent; } }
        public float B2_percent { get { return _b2_percent; } }
        public float B3_percent { get { return _b3_percent; } }
        public float B4_percent { get { return _b4_percent; } }
        public float B5_percent { get { return _b5_percent; } }
        public float B6_percent { get { return _b6_percent; } }






        public float Total
        {
            get
            {
                float sum_percent = 0;
                string[] items = (TotalByItems == null) ? new string[] { } : TotalByItems;
                // 计算值相加
                foreach (string str in items)
                {

                    switch (str)
                    {

                        case "Cha":
                            sum_percent += this.Cha;
                            break;
                        case "Zhanyoulv":
                            sum_percent += Convert.ToSingle(this.Zhanyoulv);
                            break;
                        case "DataEndDiff":
                            sum_percent += Convert.ToSingle(this.DataEndDiff);
                            break;
                        case "Sum":
                            sum_percent += this.Sum_percent;
                            break;
                        case "A":
                            sum_percent += this.Ac_percent;
                            break;
                        case "B":
                            sum_percent += this.Bg_percent;
                            break;
                        case "H":
                            sum_percent += this.H_percent;
                            break;


                        case "AAC2":
                            sum_percent += this.AAc2_percent;
                            break;
                        case "ACH2":
                            sum_percent += this.Ach2_percent;
                            break;
                        case "ABG2":
                            sum_percent += this.ABg2_percent;
                            break;
                            

                        case "BAC2":
                            sum_percent += this.BAc2_percent;
                            break;
                        case "BGH2":
                            sum_percent += this.Bgh2_percent;
                            break;
                        case "BBG2":
                            sum_percent += this.BBg2_percent;
                            break;

                        case "A1": sum_percent += this.A1_percent; break;
                        case "A2": sum_percent += this.A2_percent; break;
                        case "A3": sum_percent += this.A3_percent; break;
                        case "A4": sum_percent += this.A4_percent; break;
                        case "A5": sum_percent += this.A5_percent; break;
                        case "A6": sum_percent += this.A6_percent; break;
                        case "B1": sum_percent += this.B1_percent; break;
                        case "B2": sum_percent += this.B2_percent; break;
                        case "B3": sum_percent += this.B3_percent; break;
                        case "B4": sum_percent += this.B4_percent; break;
                        case "B5": sum_percent += this.B5_percent; break;
                        case "B6": sum_percent += this.B6_percent; break;
                        case "ColumnX":
                            sum_percent += this.ColumnX;
                            break;
                        default:
                            break;
                    }
                }
                return sum_percent;
            }
        }

        public String DeviationString
        {
            get
            {
                return string.Join("-", this._deviation.ToArray());
            }
        }
        public string[] TotalByItems { get; set; }
        public string[] SumByItems
        {
            get
            {
                return _sumByItems;
            }
            set
            {
                _sum = 0;
                _sumByItems = (value == null)?new string[] { } :value;
                // 计算值相加
                if (_sumByItems != null && _sumByItems.Length > 0)
                {
                    for (int i = 0; i < _sumByItems.Length; i++)
                    {
                        switch (_sumByItems[i])
                        {

                            case "次数差":
                                _sum += this.Cha;
                                break;
                            case "A":
                                _sum += this.Ac;
                                break;
                            case "B":
                                _sum += this.Bg;
                                break;
                            case "H":
                                _sum += this.H;
                                break;

                            case "AAC2":
                                _sum += this.AAc2;
                                break;
                            case "ACH2":
                                _sum += this.Ach2;
                                break;
                            case "ABG2":
                                _sum += this.ABg2;
                                break;

                            case "BAC2":
                                _sum += this.BAc2;
                                break;
                            case "BGH2":
                                _sum += this.Bgh2;
                                break;
                            case "BBG2":
                                _sum += this.BBg2;
                                break;
                            case "A1":
                                _sum += this.A1;
                                break;
                            case "A2":
                                _sum += this.A2;
                                break;
                            case "A3":
                                _sum += this.A3;
                                break;
                            case "A4":
                                _sum += this.A4;
                                break;
                            case "A5":
                                _sum += this.A5;
                                break;
                            case "A6":
                                _sum += this.A6;
                                break;
                            case "B1":
                                _sum += this.B1;
                                break;
                            case "B2":
                                _sum += this.B2;
                                break;
                            case "B3":
                                _sum += this.B3;
                                break;
                            case "B4":
                                _sum += this.B4;
                                break;
                            case "B5":
                                _sum += this.B5;
                                break;
                            case "B6":
                                _sum += this.B6;
                                break;



                            //case "BGH3":
                            //    _sum += this.Bgh3;
                            //    break;
                            default:
                                break;
                        }
                    }
                }
            }
        }

        public Data CopyData()
        {
            Data data = new Data();
            data._srcData = _srcData;
            data._interval= _interval;
            int[] deviation = new int[_deviation.Count];
            _deviation.CopyTo(deviation);
            data._deviation = new List<int>(deviation);
            data._time= _time;
            data._sum= _sum;
            data._sum_percent= _sum_percent;
            data._ac= _ac;
            data._ac_percent= _ac_percent;
            data._bg= _bg;
            data._bg_percent= _bg_percent;
            data._h= _h;
            data._h_percent= _h_percent;


            data._maxlen = _maxlen;
            data._cha = _cha;
            data._cha_percent = _cha_percent;
            data._blue = _blue;
            data._zhanyoulv = _zhanyoulv;
            data._chazhi = _chazhi;

            data._bac2= _bac2;
            data._bac2_percent= _bac2_percent;
            data._bbg2= _bbg2;
            data._bbg2_percent= _bbg2_percent;

            data._aac2 = _aac2;
            data._aac2_percent = _aac2_percent;
            data._abg2 = _abg2;
            data._abg2_percent = _abg2_percent;

            data._a1 = _a1;
            data._a1_percent = _a1_percent;
            data._a2 = _a2;
            data._a2_percent = _a2_percent;
            data._a3 = _a3;
            data._a3_percent = _a3_percent;
            data._a4 = _a4;
            data._a4_percent = _a4_percent;
            data._a5 = _a5;
            data._a5_percent = _a5_percent;
            data._a6 = _a6;
            data._a6_percent = _a6_percent;

            data._b1 = _b1;
            data._b1_percent = _b1_percent;
            data._b2 = _b2;
            data._b2_percent = _b2_percent;
            data._b3 = _b3;
            data._b3_percent = _b3_percent;
            data._b4 = _b4;
            data._b4_percent = _b4_percent;
            data._b5 = _b5;
            data._b5_percent = _b5_percent;
            data._b6 = _b6;
            data._b6_percent = _b6_percent;




            data._ach2= _ach2;
            data._ach2_percent= _ach2_percent;
            data._bgh2= _bgh2;
            data._bgh2_percent= _bgh2_percent;
            data._bgh3= _bgh3;
            data._bgh3_percent= _bgh3_percent;
            data._owerList = null;
            data._sumByItems = new string[_sumByItems.Length];
            _sumByItems.CopyTo(data._sumByItems, 0);
            return data;
        }

        /// <summary>
        /// Ach2%
        /// </summary>
        public int Sum
        {
            get
            {
                return _sum;
            }
        }
        /// <summary>
        /// 所在集合
        /// </summary>
        internal DataList OwerList { get { return _owerList; } set { _owerList = value; } }
        /// <summary>
        /// 更新百分比数据
        /// </summary>
        public void UpdatePercent()
        {
            _sum_percent = 0.0f;
            _ac_percent = 0.0f;
            _bg_percent = 0.0f;
            _h_percent = 0.0f;
            _cha_percent = 0.0f;

            _bac2_percent = 0.0f;
            _bbg2_percent = 0.0f;
            _aac2_percent = 0.0f;
            _abg2_percent = 0.0f;

            _bgh2_percent = 0.0f;
            _bgh3_percent = 0.0f;
           // _sum_percent = 0.0f;
            if (_owerList != null)
            {
                // AC%
                if (_owerList.ListAC.ContainsKey(_ac)) _ac_percent = _owerList.ListAC[_ac] * 100.0f / _owerList.Count;
                // BG
                if (_owerList.ListBG.ContainsKey(_bg)) _bg_percent = _owerList.ListBG[_bg] * 100.0f / _owerList.Count;
                // H
                if (_owerList.ListH.ContainsKey(_h)) _h_percent = _owerList.ListH[_h] * 100.0f / _owerList.Count;


                // BAC2
                if (_owerList.ListBAC2.ContainsKey(_bac2)) _bac2_percent = _owerList.ListBAC2[_bac2] * 100.0f / _owerList.Count;
                // BBG2
                if (_owerList.ListBBG2.ContainsKey(_bbg2)) _bbg2_percent = _owerList.ListBBG2[_bbg2] * 100.0f / _owerList.Count;
               

                // ABG2
                if (_owerList.ListABG2.ContainsKey(_abg2)) _abg2_percent = _owerList.ListABG2[_abg2] * 100.0f / _owerList.Count;
                // AAC2
                if (_owerList.ListAAC2.ContainsKey(_aac2)) _aac2_percent = _owerList.ListAAC2[_aac2] * 100.0f / _owerList.Count;

                //a1-a6
                if (_owerList.ListA1.ContainsKey(_a1)) _a1_percent = _owerList.ListA1[_a1] * 100.0f / _owerList.Count;
                if (_owerList.ListA2.ContainsKey(_a2)) _a2_percent = _owerList.ListA2[_a2] * 100.0f / _owerList.Count;
                if (_owerList.ListA3.ContainsKey(_a3)) _a3_percent = _owerList.ListA3[_a3] * 100.0f / _owerList.Count;
                if (_owerList.ListA4.ContainsKey(_a4)) _a4_percent = _owerList.ListA4[_a4] * 100.0f / _owerList.Count;
                if (_owerList.ListA5.ContainsKey(_a5)) _a5_percent = _owerList.ListA5[_a5] * 100.0f / _owerList.Count;
                if (_owerList.ListA6.ContainsKey(_a6)) _a6_percent = _owerList.ListA6[_a6] * 100.0f / _owerList.Count;

                if (_owerList.ListB1.ContainsKey(_b1)) _b1_percent = _owerList.ListB1[_b1] * 100.0f / _owerList.Count;
                if (_owerList.ListB2.ContainsKey(_b2)) _b2_percent = _owerList.ListB2[_b2] * 100.0f / _owerList.Count;
                if (_owerList.ListB3.ContainsKey(_b3)) _b3_percent = _owerList.ListB3[_b3] * 100.0f / _owerList.Count;
                if (_owerList.ListB4.ContainsKey(_b4)) _b4_percent = _owerList.ListB4[_b4] * 100.0f / _owerList.Count;
                if (_owerList.ListB5.ContainsKey(_b5)) _b5_percent = _owerList.ListB5[_b5] * 100.0f / _owerList.Count;
                if (_owerList.ListB6.ContainsKey(_b6)) _b6_percent = _owerList.ListB6[_b6] * 100.0f / _owerList.Count;



                // Cha
                if (_owerList.ListCha.ContainsKey(_cha)) _cha_percent = _owerList.ListCha[_cha] * 100.0f / _owerList.Count;

                // BGH2
                if (_owerList.ListACH2.ContainsKey(_ach2)) _ach2_percent = _owerList.ListACH2[_ach2] * 100.0f / _owerList.Count;
                // BGH2
                if (_owerList.ListBGH2.ContainsKey(_bgh2)) _bgh2_percent = _owerList.ListBGH2[_bgh2] * 100.0f / _owerList.Count;
                // BGH3
                if (_owerList.ListBGH3.ContainsKey(_bgh3)) _bgh3_percent = _owerList.ListBGH3[_bgh3] * 100.0f / _owerList.Count;
                // Sum
                if (_owerList.ListSum.ContainsKey(_sum)) {

                    if (_sum < 0)
                    {
                        _sum_percent = -_owerList.ListSum[_sum] * 100.0f / _owerList.Count;
                    }
                    else
                    {
                        _sum_percent = _owerList.ListSum[_sum] * 100.0f / _owerList.Count;
                    }
                    
                
                } 
            }
        }

        // 数据末端差
        public int DataEndDiff
        {
            get
            {
                if (CurrentRawDataList == null) return 0;
                int lastIndex = -1;
                for (int i = CurrentRawDataList.Count - 1; i >= 0; i--)
                {
                    if (CurrentRawDataList[i] == this.SrcData)
                    {
                        lastIndex = i;
                        break;
                    }
                }
                if (lastIndex == -1) return 0;
                int distanceToEnd = CurrentRawDataList.Count - lastIndex - 1;
                int avgInterval = this.Interval;
                return distanceToEnd - avgInterval;
            }
        }

        // 新增功能相关属性
        /// <summary>
        /// 理论间隔 = 总数据数 / (出现次数 + 1)
        /// </summary>
        public float TheoreticalInterval 
        { 
            get { return _theoreticalInterval; } 
            set { _theoreticalInterval = value; } 
        }

        /// <summary>
        /// Z值 = Y + (X/2)
        /// </summary>
        public float ZValue 
        { 
            get { return _zValue; } 
            set { _zValue = value; } 
        }

        /// <summary>
        /// 新数据间隔Y（间隔正负均值）
        /// </summary>
        public float NewDataIntervalY 
        { 
            get { return _newDataIntervalY; } 
            set { _newDataIntervalY = value; } 
        }

        /// <summary>
        /// 新末端差X（末端差大小均值）
        /// </summary>
        public float NewEndDiffX 
        { 
            get { return _newEndDiffX; } 
            set { _newEndDiffX = value; } 
        }

        /// <summary>
        /// 差值 = 理论间隔 - Z值
        /// </summary>
        public float DiffValue 
        { 
            get { return _diffValue; } 
            set { _diffValue = value; } 
        }

        /// <summary>
        /// 是否为异常值
        /// </summary>
        public bool IsAnomalyValue 
        { 
            get { return _isAnomalyValue; } 
            set { _isAnomalyValue = value; } 
        }

        /// <summary>
        /// 是否为新异常值
        /// </summary>
        public bool IsNewAnomalyValue 
        { 
            get { return _isNewAnomalyValue; } 
            set { _isNewAnomalyValue = value; } 
        }

        /// <summary>
        /// 列X = X-(z值*次数+理论间隔)
        /// </summary>
        public float ColumnX 
        { 
            get { return _columnX; } 
            set { _columnX = value; } 
        }

        // 差% = （数据平均间隔+数据末端差）/数据平均间隔 × 100
        public float Difference_percent
        {
            get
            {
                float denom = this.Interval;
                if (denom == 0.0f) return 0.0f;
                return (this.Interval + this.DataEndDiff) * 100.0f / denom;
            }
        }

        // 新差% = （新数据间隔Y+新末端差X）/新数据间隔Y × 100
        public float NewDifference_percent
        {
            get
            {
                float denom = this.NewDataIntervalY;
                if (denom == 0.0f) return 0.0f;
                return (this.NewDataIntervalY + this.NewEndDiffX) * 100.0f / denom;
            }
        }

        /// <summary>
        /// 数据出现次数 - 统计出现次数列值相同的数据个数
        /// </summary>
        public int DataCount 
        { 
            get 
            {
                if (_owerList != null)
                {
                    // 统计出现次数列值相同的数据个数
                    int count = 0;
                    foreach (Data data in _owerList)
                    {
                        if (data.Time == this.Time)
                        {
                            count++;
                        }
                    }
                    return count;
                }
                return 1;
            }
        }

        /// <summary>
        /// 列X2 = （Y值*次数）+ （Y+X）+（理论间隔* 手动输入的数据 % ）
        /// 其中Y值=NewDataIntervalY，X=NewEndDiffX，次数=DataCount
        /// 手动输入的数据%需要从外部设置
        /// </summary>
        public float ColumnX2 
        { 
            get 
            {
                // Y值*次数
                float part1 = _newDataIntervalY * Time;
                
                // Y+X
                float part2 = _newDataIntervalY + _newEndDiffX;
                
                // 理论间隔* 手动输入的数据 %
                // 这里假设手动输入的数据%存储在某个静态变量中，暂时设为0
                float manualInputPercent = ManualInputPercent;
                float part3 = _theoreticalInterval * manualInputPercent;
                
                return part1 + part2 + part3;
            }
        }

        // 静态属性：手动输入的数据百分比
        public static float ManualInputPercent { get; set; } = 0.0f;
    }
}
